package com.intel.factorytest.activity;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import com.intel.factorytest.R;
import java.util.Date;
import java.text.SimpleDateFormat;
import android.os.Handler;
import android.os.Message;
import java.util.Timer;
import java.util.TimerTask;

public class RTC  extends BaseActivity {

    static final String TAG = "RTC";
    private TextView mcTestText;
    SimpleDateFormat sDateFormat;
    final static int UPDATE_TIMES = 0;
    private Timer mTimer;

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.rtc);
        initView();
        mcTestText = (TextView)findViewById(R.id.rtc_get_time);

        String s = String.valueOf(System.currentTimeMillis()/1000);
        sDateFormat =   new SimpleDateFormat("hh:mm:ss");
        String date = sDateFormat.format(new Date());
        Log.i(TAG, " rtc value = " + date);
        mcTestText.setText("RTC get real value is : " + date);

    }


    protected void initView() {
         super.initView();
     }

    private Handler mHandler = new Handler(){

        public void handleMessage(Message msg){
            int what = msg.what;
            if(what == UPDATE_TIMES){
                String date = sDateFormat.format(new Date());
                Log.i(TAG, " refresh rtc value = " + date);
                mcTestText.setText("RTC get real value is : " + date);

            }
        }
    };

    Runnable mRunnable = new Runnable(){
        @Override
        public void run() {
            Message msg = new Message();
            msg.what =  1;
            mHandler.sendMessage(msg);
        }
    };

    @Override
    protected void onResume() {
        super.onResume();
        mTimer = new Timer();
        mTimer.schedule(new TimerTask() {

            @Override
            public void run() {
                mHandler.sendEmptyMessage(UPDATE_TIMES);
            }

        }, 500, 500);
        mItemTestFinish = true;//add by wangsm
    }

}
